ef45f8
@@ -21,6 +21,7 @@
 import java.util.*;
 import java.util.Map.Entry;
 
+import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.metastore.api.Order;
 import org.apache.hadoop.hive.ql.exec.GroupByOperator;
 import org.apache.hadoop.hive.ql.exec.JoinOperator;
@@ -153,32 +154,34 @@
public boolean checkBucketedTable(Table tbl, ParseContext pGraphContext,
         return false;
       }
 
-      if (tbl.isPartitioned()) {
-        List<Partition> partitions = prunedParts.getNotDeniedPartns();
-        // construct a mapping of (Partition->bucket file names) and (Partition -> bucket number)
-        if (!partitions.isEmpty()) {
-          for (Partition p : partitions) {
-            List<String> fileNames = 
-                AbstractBucketJoinProc.getBucketFilePathsOfPartition(p.getDataLocation(), 
-                    pGraphContext);
-            // The number of files for the table should be same as number of
-            // buckets.
-            if (fileNames.size() != 0 && fileNames.size() != numBuckets) {
-              return false;
+      // Tez can handle unpopulated buckets
+      if (!HiveConf.getVar(pGraphContext.getConf(), HiveConf.ConfVars.HIVE_EXECUTION_ENGINE).equals("tez")) {
+        if (tbl.isPartitioned()) {
+          List<Partition> partitions = prunedParts.getNotDeniedPartns();
+          // construct a mapping of (Partition->bucket file names) and (Partition -> bucket number)
+          if (!partitions.isEmpty()) {
+            for (Partition p : partitions) {
+              List<String> fileNames =
+                      AbstractBucketJoinProc.getBucketFilePathsOfPartition(p.getDataLocation(),
+                              pGraphContext);
+              // The number of files for the table should be same as number of
+              // buckets.
+              if (fileNames.size() != 0 && fileNames.size() != numBuckets) {
+                return false;
+              }
             }
           }
-        }
-      } else {
-
-        List<String> fileNames =
-            AbstractBucketJoinProc.getBucketFilePathsOfPartition(tbl.getDataLocation(),
-                pGraphContext);
-        // The number of files for the table should be same as number of buckets.
-        if (fileNames.size() != 0 && fileNames.size() != numBuckets) {
-          return false;
+        } else {
+
+          List<String> fileNames =
+                  AbstractBucketJoinProc.getBucketFilePathsOfPartition(tbl.getDataLocation(),
+                          pGraphContext);
+          // The number of files for the table should be same as number of buckets.
+          if (fileNames.size() != 0 && fileNames.size() != numBuckets) {
+            return false;
+          }
         }
       }
-
       return true;
     }
 
